#include "jvm.h"
#include <vector>

#define EMBEDDED_JAR L"JSTART_JAR"

static const BYTE EMBEDDED_CLASS_LOADER_CLASS[] = {
    0xCA, 0xFE, 0xBA, 0xBE, 0x00, 0x00, 0x00, 0x34, 0x00, 0xB7, 0x07, 0x00, 0x60, 0x0A, 0x00, 0x61, 0x00, 0x62, 0x0A,
    0x00, 0x61, 0x00, 0x63, 0x0A, 0x00, 0x2D, 0x00, 0x64, 0x0A, 0x00, 0x2C, 0x00, 0x65, 0x07, 0x00, 0x66, 0x09, 0x00,
    0x2C, 0x00, 0x67, 0x0B, 0x00, 0x68, 0x00, 0x69, 0x07, 0x00, 0x46, 0x0A, 0x00, 0x06, 0x00, 0x6A, 0x0A, 0x00, 0x2A,
    0x00, 0x6B, 0x08, 0x00, 0x6C, 0x0A, 0x00, 0x2A, 0x00, 0x6D, 0x09, 0x00, 0x2C, 0x00, 0x6E, 0x0B, 0x00, 0x68, 0x00,
    0x6F, 0x0A, 0x00, 0x2C, 0x00, 0x70, 0x07, 0x00, 0x71, 0x0A, 0x00, 0x11, 0x00, 0x72, 0x07, 0x00, 0x73, 0x0A, 0x00,
    0x13, 0x00, 0x74, 0x08, 0x00, 0x75, 0x0A, 0x00, 0x13, 0x00, 0x76, 0x0A, 0x00, 0x13, 0x00, 0x77, 0x0A, 0x00, 0x01,
    0x00, 0x72, 0x07, 0x00, 0x78, 0x0A, 0x00, 0x2D, 0x00, 0x79, 0x07, 0x00, 0x7A, 0x0A, 0x00, 0x1B, 0x00, 0x74, 0x07,
    0x00, 0x7B, 0x0A, 0x00, 0x1D, 0x00, 0x7C, 0x0A, 0x00, 0x1D, 0x00, 0x7D, 0x0A, 0x00, 0x59, 0x00, 0x7E, 0x07, 0x00,
    0x7F, 0x0A, 0x00, 0x21, 0x00, 0x80, 0x0A, 0x00, 0x1D, 0x00, 0x81, 0x0A, 0x00, 0x21, 0x00, 0x82, 0x0A, 0x00, 0x59,
    0x00, 0x83, 0x0B, 0x00, 0x68, 0x00, 0x84, 0x0A, 0x00, 0x21, 0x00, 0x85, 0x0A, 0x00, 0x1D, 0x00, 0x86, 0x0B, 0x00,
    0x68, 0x00, 0x87, 0x07, 0x00, 0x88, 0x0A, 0x00, 0x2A, 0x00, 0x89, 0x07, 0x00, 0x8A, 0x07, 0x00, 0x8B, 0x01, 0x00,
    0x05, 0x6E, 0x61, 0x6D, 0x65, 0x73, 0x01, 0x00, 0x10, 0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x75, 0x74, 0x69, 0x6C,
    0x2F, 0x4C, 0x69, 0x73, 0x74, 0x3B, 0x01, 0x00, 0x09, 0x53, 0x69, 0x67, 0x6E, 0x61, 0x74, 0x75, 0x72, 0x65, 0x01,
    0x00, 0x24, 0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x75, 0x74, 0x69, 0x6C, 0x2F, 0x4C, 0x69, 0x73, 0x74, 0x3C, 0x4C,
    0x6A, 0x61, 0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67, 0x2F, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3B, 0x3E, 0x3B,
    0x01, 0x00, 0x05, 0x62, 0x79, 0x74, 0x65, 0x73, 0x01, 0x00, 0x14, 0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x75, 0x74,
    0x69, 0x6C, 0x2F, 0x4C, 0x69, 0x73, 0x74, 0x3C, 0x5B, 0x42, 0x3E, 0x3B, 0x01, 0x00, 0x06, 0x3C, 0x69, 0x6E, 0x69,
    0x74, 0x3E, 0x01, 0x00, 0x03, 0x28, 0x29, 0x56, 0x01, 0x00, 0x04, 0x43, 0x6F, 0x64, 0x65, 0x01, 0x00, 0x0F, 0x4C,
    0x69, 0x6E, 0x65, 0x4E, 0x75, 0x6D, 0x62, 0x65, 0x72, 0x54, 0x61, 0x62, 0x6C, 0x65, 0x01, 0x00, 0x12, 0x4C, 0x6F,
    0x63, 0x61, 0x6C, 0x56, 0x61, 0x72, 0x69, 0x61, 0x62, 0x6C, 0x65, 0x54, 0x61, 0x62, 0x6C, 0x65, 0x01, 0x00, 0x04,
    0x74, 0x68, 0x69, 0x73, 0x01, 0x00, 0x20, 0x4C, 0x6A, 0x73, 0x74, 0x61, 0x72, 0x74, 0x2F, 0x65, 0x78, 0x65, 0x2F,
    0x45, 0x6D, 0x62, 0x65, 0x64, 0x64, 0x65, 0x64, 0x43, 0x6C, 0x61, 0x73, 0x73, 0x4C, 0x6F, 0x61, 0x64, 0x65, 0x72,
    0x3B, 0x01, 0x00, 0x13, 0x67, 0x65, 0x74, 0x52, 0x65, 0x73, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x41, 0x73, 0x53, 0x74,
    0x72, 0x65, 0x61, 0x6D, 0x01, 0x00, 0x29, 0x28, 0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67, 0x2F,
    0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3B, 0x29, 0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x69, 0x6F, 0x2F, 0x49, 0x6E,
    0x70, 0x75, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6D, 0x3B, 0x01, 0x00, 0x04, 0x6E, 0x61, 0x6D, 0x65, 0x01, 0x00,
    0x12, 0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67, 0x2F, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3B,
    0x01, 0x00, 0x05, 0x69, 0x6E, 0x64, 0x65, 0x78, 0x01, 0x00, 0x01, 0x49, 0x01, 0x00, 0x0D, 0x53, 0x74, 0x61, 0x63,
    0x6B, 0x4D, 0x61, 0x70, 0x54, 0x61, 0x62, 0x6C, 0x65, 0x07, 0x00, 0x8C, 0x01, 0x00, 0x09, 0x66, 0x69, 0x6E, 0x64,
    0x43, 0x6C, 0x61, 0x73, 0x73, 0x01, 0x00, 0x25, 0x28, 0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67,
    0x2F, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3B, 0x29, 0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67,
    0x2F, 0x43, 0x6C, 0x61, 0x73, 0x73, 0x3B, 0x01, 0x00, 0x09, 0x62, 0x79, 0x74, 0x65, 0x43, 0x6F, 0x64, 0x65, 0x73,
    0x01, 0x00, 0x02, 0x5B, 0x42, 0x01, 0x00, 0x09, 0x63, 0x6C, 0x61, 0x73, 0x73, 0x4E, 0x61, 0x6D, 0x65, 0x01, 0x00,
    0x0A, 0x45, 0x78, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6F, 0x6E, 0x73, 0x01, 0x00, 0x28, 0x28, 0x4C, 0x6A, 0x61, 0x76,
    0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67, 0x2F, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3B, 0x29, 0x4C, 0x6A, 0x61, 0x76,
    0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67, 0x2F, 0x43, 0x6C, 0x61, 0x73, 0x73, 0x3C, 0x2A, 0x3E, 0x3B, 0x01, 0x00, 0x0C,
    0x66, 0x69, 0x6E, 0x64, 0x52, 0x65, 0x73, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x01, 0x00, 0x22, 0x28, 0x4C, 0x6A, 0x61,
    0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67, 0x2F, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3B, 0x29, 0x4C, 0x6A, 0x61,
    0x76, 0x61, 0x2F, 0x6E, 0x65, 0x74, 0x2F, 0x55, 0x52, 0x4C, 0x3B, 0x01, 0x00, 0x07, 0x69, 0x67, 0x6E, 0x6F, 0x72,
    0x65, 0x64, 0x01, 0x00, 0x20, 0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x6E, 0x65, 0x74, 0x2F, 0x4D, 0x61, 0x6C, 0x66,
    0x6F, 0x72, 0x6D, 0x65, 0x64, 0x55, 0x52, 0x4C, 0x45, 0x78, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6F, 0x6E, 0x3B, 0x01,
    0x00, 0x0F, 0x6C, 0x6F, 0x61, 0x64, 0x45, 0x6D, 0x62, 0x65, 0x64, 0x64, 0x65, 0x64, 0x4A, 0x61, 0x72, 0x01, 0x00,
    0x05, 0x28, 0x5B, 0x42, 0x29, 0x56, 0x01, 0x00, 0x03, 0x6F, 0x75, 0x74, 0x01, 0x00, 0x1F, 0x4C, 0x6A, 0x61, 0x76,
    0x61, 0x2F, 0x69, 0x6F, 0x2F, 0x42, 0x79, 0x74, 0x65, 0x41, 0x72, 0x72, 0x61, 0x79, 0x4F, 0x75, 0x74, 0x70, 0x75,
    0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6D, 0x3B, 0x01, 0x00, 0x03, 0x6C, 0x65, 0x6E, 0x01, 0x00, 0x08, 0x6A, 0x61,
    0x72, 0x42, 0x79, 0x74, 0x65, 0x73, 0x01, 0x00, 0x03, 0x6A, 0x69, 0x73, 0x01, 0x00, 0x1E, 0x4C, 0x6A, 0x61, 0x76,
    0x61, 0x2F, 0x75, 0x74, 0x69, 0x6C, 0x2F, 0x6A, 0x61, 0x72, 0x2F, 0x4A, 0x61, 0x72, 0x49, 0x6E, 0x70, 0x75, 0x74,
    0x53, 0x74, 0x72, 0x65, 0x61, 0x6D, 0x3B, 0x01, 0x00, 0x05, 0x65, 0x6E, 0x74, 0x72, 0x79, 0x01, 0x00, 0x18, 0x4C,
    0x6A, 0x61, 0x76, 0x61, 0x2F, 0x75, 0x74, 0x69, 0x6C, 0x2F, 0x6A, 0x61, 0x72, 0x2F, 0x4A, 0x61, 0x72, 0x45, 0x6E,
    0x74, 0x72, 0x79, 0x3B, 0x01, 0x00, 0x06, 0x62, 0x75, 0x66, 0x66, 0x65, 0x72, 0x07, 0x00, 0x8D, 0x07, 0x00, 0x8E,
    0x01, 0x00, 0x09, 0x66, 0x69, 0x6E, 0x64, 0x42, 0x79, 0x74, 0x65, 0x73, 0x01, 0x00, 0x15, 0x28, 0x4C, 0x6A, 0x61,
    0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67, 0x2F, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3B, 0x29, 0x49, 0x01, 0x00,
    0x01, 0x69, 0x01, 0x00, 0x0A, 0x53, 0x6F, 0x75, 0x72, 0x63, 0x65, 0x46, 0x69, 0x6C, 0x65, 0x01, 0x00, 0x18, 0x45,
    0x6D, 0x62, 0x65, 0x64, 0x64, 0x65, 0x64, 0x43, 0x6C, 0x61, 0x73, 0x73, 0x4C, 0x6F, 0x61, 0x64, 0x65, 0x72, 0x2E,
    0x6A, 0x61, 0x76, 0x61, 0x01, 0x00, 0x0C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x6E, 0x65, 0x74, 0x2F, 0x55, 0x52, 0x4C,
    0x07, 0x00, 0x8F, 0x0C, 0x00, 0x90, 0x00, 0x91, 0x0C, 0x00, 0x92, 0x00, 0x93, 0x0C, 0x00, 0x34, 0x00, 0x94, 0x0C,
    0x00, 0x5B, 0x00, 0x5C, 0x01, 0x00, 0x1C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x69, 0x6F, 0x2F, 0x42, 0x79, 0x74, 0x65,
    0x41, 0x72, 0x72, 0x61, 0x79, 0x49, 0x6E, 0x70, 0x75, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6D, 0x0C, 0x00, 0x32,
    0x00, 0x2F, 0x07, 0x00, 0x95, 0x0C, 0x00, 0x96, 0x00, 0x97, 0x0C, 0x00, 0x34, 0x00, 0x4F, 0x0C, 0x00, 0x98, 0x00,
    0x99, 0x01, 0x00, 0x06, 0x2E, 0x63, 0x6C, 0x61, 0x73, 0x73, 0x0C, 0x00, 0x9A, 0x00, 0x9B, 0x0C, 0x00, 0x2E, 0x00,
    0x2F, 0x0C, 0x00, 0x9C, 0x00, 0x97, 0x0C, 0x00, 0x9D, 0x00, 0x9E, 0x01, 0x00, 0x20, 0x6A, 0x61, 0x76, 0x61, 0x2F,
    0x6C, 0x61, 0x6E, 0x67, 0x2F, 0x43, 0x6C, 0x61, 0x73, 0x73, 0x4E, 0x6F, 0x74, 0x46, 0x6F, 0x75, 0x6E, 0x64, 0x45,
    0x78, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6F, 0x6E, 0x0C, 0x00, 0x34, 0x00, 0x9F, 0x01, 0x00, 0x17, 0x6A, 0x61, 0x76,
    0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67, 0x2F, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x42, 0x75, 0x69, 0x6C, 0x64, 0x65,
    0x72, 0x0C, 0x00, 0x34, 0x00, 0x35, 0x01, 0x00, 0x07, 0x72, 0x65, 0x73, 0x3A, 0x2F, 0x2F, 0x2F, 0x0C, 0x00, 0xA0,
    0x00, 0xA1, 0x0C, 0x00, 0xA2, 0x00, 0xA3, 0x01, 0x00, 0x1E, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x6E, 0x65, 0x74, 0x2F,
    0x4D, 0x61, 0x6C, 0x66, 0x6F, 0x72, 0x6D, 0x65, 0x64, 0x55, 0x52, 0x4C, 0x45, 0x78, 0x63, 0x65, 0x70, 0x74, 0x69,
    0x6F, 0x6E, 0x0C, 0x00, 0x4A, 0x00, 0x4B, 0x01, 0x00, 0x13, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x75, 0x74, 0x69, 0x6C,
    0x2F, 0x41, 0x72, 0x72, 0x61, 0x79, 0x4C, 0x69, 0x73, 0x74, 0x01, 0x00, 0x1C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x75,
    0x74, 0x69, 0x6C, 0x2F, 0x6A, 0x61, 0x72, 0x2F, 0x4A, 0x61, 0x72, 0x49, 0x6E, 0x70, 0x75, 0x74, 0x53, 0x74, 0x72,
    0x65, 0x61, 0x6D, 0x0C, 0x00, 0x34, 0x00, 0xA4, 0x0C, 0x00, 0xA5, 0x00, 0xA6, 0x0C, 0x00, 0xA7, 0x00, 0xA8, 0x01,
    0x00, 0x1D, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x69, 0x6F, 0x2F, 0x42, 0x79, 0x74, 0x65, 0x41, 0x72, 0x72, 0x61, 0x79,
    0x4F, 0x75, 0x74, 0x70, 0x75, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6D, 0x0C, 0x00, 0x34, 0x00, 0xA9, 0x0C, 0x00,
    0xAA, 0x00, 0xAB, 0x0C, 0x00, 0xAC, 0x00, 0xAD, 0x0C, 0x00, 0xAE, 0x00, 0xA3, 0x0C, 0x00, 0xAF, 0x00, 0xB0, 0x0C,
    0x00, 0xB1, 0x00, 0xB2, 0x0C, 0x00, 0xB3, 0x00, 0x35, 0x0C, 0x00, 0xB4, 0x00, 0xB5, 0x01, 0x00, 0x10, 0x6A, 0x61,
    0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67, 0x2F, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x0C, 0x00, 0xB6, 0x00, 0xB0,
    0x01, 0x00, 0x1E, 0x6A, 0x73, 0x74, 0x61, 0x72, 0x74, 0x2F, 0x65, 0x78, 0x65, 0x2F, 0x45, 0x6D, 0x62, 0x65, 0x64,
    0x64, 0x65, 0x64, 0x43, 0x6C, 0x61, 0x73, 0x73, 0x4C, 0x6F, 0x61, 0x64, 0x65, 0x72, 0x01, 0x00, 0x17, 0x6A, 0x61,
    0x76, 0x61, 0x2F, 0x6E, 0x65, 0x74, 0x2F, 0x55, 0x52, 0x4C, 0x43, 0x6C, 0x61, 0x73, 0x73, 0x4C, 0x6F, 0x61, 0x64,
    0x65, 0x72, 0x01, 0x00, 0x13, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x69, 0x6F, 0x2F, 0x49, 0x6E, 0x70, 0x75, 0x74, 0x53,
    0x74, 0x72, 0x65, 0x61, 0x6D, 0x01, 0x00, 0x16, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x75, 0x74, 0x69, 0x6C, 0x2F, 0x6A,
    0x61, 0x72, 0x2F, 0x4A, 0x61, 0x72, 0x45, 0x6E, 0x74, 0x72, 0x79, 0x01, 0x00, 0x13, 0x6A, 0x61, 0x76, 0x61, 0x2F,
    0x69, 0x6F, 0x2F, 0x49, 0x4F, 0x45, 0x78, 0x63, 0x65, 0x70, 0x74, 0x69, 0x6F, 0x6E, 0x01, 0x00, 0x10, 0x6A, 0x61,
    0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67, 0x2F, 0x54, 0x68, 0x72, 0x65, 0x61, 0x64, 0x01, 0x00, 0x0D, 0x63, 0x75,
    0x72, 0x72, 0x65, 0x6E, 0x74, 0x54, 0x68, 0x72, 0x65, 0x61, 0x64, 0x01, 0x00, 0x14, 0x28, 0x29, 0x4C, 0x6A, 0x61,
    0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67, 0x2F, 0x54, 0x68, 0x72, 0x65, 0x61, 0x64, 0x3B, 0x01, 0x00, 0x15, 0x67,
    0x65, 0x74, 0x43, 0x6F, 0x6E, 0x74, 0x65, 0x78, 0x74, 0x43, 0x6C, 0x61, 0x73, 0x73, 0x4C, 0x6F, 0x61, 0x64, 0x65,
    0x72, 0x01, 0x00, 0x19, 0x28, 0x29, 0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67, 0x2F, 0x43, 0x6C,
    0x61, 0x73, 0x73, 0x4C, 0x6F, 0x61, 0x64, 0x65, 0x72, 0x3B, 0x01, 0x00, 0x29, 0x28, 0x5B, 0x4C, 0x6A, 0x61, 0x76,
    0x61, 0x2F, 0x6E, 0x65, 0x74, 0x2F, 0x55, 0x52, 0x4C, 0x3B, 0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E,
    0x67, 0x2F, 0x43, 0x6C, 0x61, 0x73, 0x73, 0x4C, 0x6F, 0x61, 0x64, 0x65, 0x72, 0x3B, 0x29, 0x56, 0x01, 0x00, 0x0E,
    0x6A, 0x61, 0x76, 0x61, 0x2F, 0x75, 0x74, 0x69, 0x6C, 0x2F, 0x4C, 0x69, 0x73, 0x74, 0x01, 0x00, 0x03, 0x67, 0x65,
    0x74, 0x01, 0x00, 0x15, 0x28, 0x49, 0x29, 0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67, 0x2F, 0x4F,
    0x62, 0x6A, 0x65, 0x63, 0x74, 0x3B, 0x01, 0x00, 0x07, 0x72, 0x65, 0x70, 0x6C, 0x61, 0x63, 0x65, 0x01, 0x00, 0x16,
    0x28, 0x43, 0x43, 0x29, 0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67, 0x2F, 0x53, 0x74, 0x72, 0x69,
    0x6E, 0x67, 0x3B, 0x01, 0x00, 0x06, 0x63, 0x6F, 0x6E, 0x63, 0x61, 0x74, 0x01, 0x00, 0x26, 0x28, 0x4C, 0x6A, 0x61,
    0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67, 0x2F, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3B, 0x29, 0x4C, 0x6A, 0x61,
    0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67, 0x2F, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3B, 0x01, 0x00, 0x06, 0x72,
    0x65, 0x6D, 0x6F, 0x76, 0x65, 0x01, 0x00, 0x0B, 0x64, 0x65, 0x66, 0x69, 0x6E, 0x65, 0x43, 0x6C, 0x61, 0x73, 0x73,
    0x01, 0x00, 0x29, 0x28, 0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67, 0x2F, 0x53, 0x74, 0x72, 0x69,
    0x6E, 0x67, 0x3B, 0x5B, 0x42, 0x49, 0x49, 0x29, 0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67, 0x2F,
    0x43, 0x6C, 0x61, 0x73, 0x73, 0x3B, 0x01, 0x00, 0x15, 0x28, 0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E,
    0x67, 0x2F, 0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3B, 0x29, 0x56, 0x01, 0x00, 0x06, 0x61, 0x70, 0x70, 0x65, 0x6E,
    0x64, 0x01, 0x00, 0x2D, 0x28, 0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67, 0x2F, 0x53, 0x74, 0x72,
    0x69, 0x6E, 0x67, 0x3B, 0x29, 0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67, 0x2F, 0x53, 0x74, 0x72,
    0x69, 0x6E, 0x67, 0x42, 0x75, 0x69, 0x6C, 0x64, 0x65, 0x72, 0x3B, 0x01, 0x00, 0x08, 0x74, 0x6F, 0x53, 0x74, 0x72,
    0x69, 0x6E, 0x67, 0x01, 0x00, 0x14, 0x28, 0x29, 0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67, 0x2F,
    0x53, 0x74, 0x72, 0x69, 0x6E, 0x67, 0x3B, 0x01, 0x00, 0x18, 0x28, 0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x69, 0x6F,
    0x2F, 0x49, 0x6E, 0x70, 0x75, 0x74, 0x53, 0x74, 0x72, 0x65, 0x61, 0x6D, 0x3B, 0x29, 0x56, 0x01, 0x00, 0x0F, 0x67,
    0x65, 0x74, 0x4E, 0x65, 0x78, 0x74, 0x4A, 0x61, 0x72, 0x45, 0x6E, 0x74, 0x72, 0x79, 0x01, 0x00, 0x1A, 0x28, 0x29,
    0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x75, 0x74, 0x69, 0x6C, 0x2F, 0x6A, 0x61, 0x72, 0x2F, 0x4A, 0x61, 0x72, 0x45,
    0x6E, 0x74, 0x72, 0x79, 0x3B, 0x01, 0x00, 0x0B, 0x69, 0x73, 0x44, 0x69, 0x72, 0x65, 0x63, 0x74, 0x6F, 0x72, 0x79,
    0x01, 0x00, 0x03, 0x28, 0x29, 0x5A, 0x01, 0x00, 0x04, 0x28, 0x49, 0x29, 0x56, 0x01, 0x00, 0x04, 0x72, 0x65, 0x61,
    0x64, 0x01, 0x00, 0x05, 0x28, 0x5B, 0x42, 0x29, 0x49, 0x01, 0x00, 0x05, 0x77, 0x72, 0x69, 0x74, 0x65, 0x01, 0x00,
    0x07, 0x28, 0x5B, 0x42, 0x49, 0x49, 0x29, 0x56, 0x01, 0x00, 0x07, 0x67, 0x65, 0x74, 0x4E, 0x61, 0x6D, 0x65, 0x01,
    0x00, 0x03, 0x61, 0x64, 0x64, 0x01, 0x00, 0x15, 0x28, 0x4C, 0x6A, 0x61, 0x76, 0x61, 0x2F, 0x6C, 0x61, 0x6E, 0x67,
    0x2F, 0x4F, 0x62, 0x6A, 0x65, 0x63, 0x74, 0x3B, 0x29, 0x5A, 0x01, 0x00, 0x0B, 0x74, 0x6F, 0x42, 0x79, 0x74, 0x65,
    0x41, 0x72, 0x72, 0x61, 0x79, 0x01, 0x00, 0x04, 0x28, 0x29, 0x5B, 0x42, 0x01, 0x00, 0x05, 0x63, 0x6C, 0x6F, 0x73,
    0x65, 0x01, 0x00, 0x04, 0x73, 0x69, 0x7A, 0x65, 0x01, 0x00, 0x03, 0x28, 0x29, 0x49, 0x01, 0x00, 0x06, 0x65, 0x71,
    0x75, 0x61, 0x6C, 0x73, 0x00, 0x21, 0x00, 0x2C, 0x00, 0x2D, 0x00, 0x00, 0x00, 0x02, 0x00, 0x0A, 0x00, 0x2E, 0x00,
    0x2F, 0x00, 0x01, 0x00, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x31, 0x00, 0x0A, 0x00, 0x32, 0x00, 0x2F, 0x00, 0x01,
    0x00, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x33, 0x00, 0x06, 0x00, 0x01, 0x00, 0x34, 0x00, 0x35, 0x00, 0x01, 0x00,
    0x36, 0x00, 0x00, 0x00, 0x3D, 0x00, 0x03, 0x00, 0x01, 0x00, 0x00, 0x00, 0x0F, 0x2A, 0x03, 0xBD, 0x00, 0x01, 0xB8,
    0x00, 0x02, 0xB6, 0x00, 0x03, 0xB7, 0x00, 0x04, 0xB1, 0x00, 0x00, 0x00, 0x02, 0x00, 0x37, 0x00, 0x00, 0x00, 0x0A,
    0x00, 0x02, 0x00, 0x00, 0x00, 0x1C, 0x00, 0x0E, 0x00, 0x1D, 0x00, 0x38, 0x00, 0x00, 0x00, 0x0C, 0x00, 0x01, 0x00,
    0x00, 0x00, 0x0F, 0x00, 0x39, 0x00, 0x3A, 0x00, 0x00, 0x00, 0x01, 0x00, 0x3B, 0x00, 0x3C, 0x00, 0x01, 0x00, 0x36,
    0x00, 0x00, 0x00, 0x73, 0x00, 0x04, 0x00, 0x03, 0x00, 0x00, 0x00, 0x21, 0x2B, 0xB8, 0x00, 0x05, 0x3D, 0x1C, 0x9B,
    0x00, 0x19, 0xBB, 0x00, 0x06, 0x59, 0xB2, 0x00, 0x07, 0x1C, 0xB9, 0x00, 0x08, 0x02, 0x00, 0xC0, 0x00, 0x09, 0xB7,
    0x00, 0x0A, 0xA7, 0x00, 0x04, 0x01, 0xB0, 0x00, 0x00, 0x00, 0x03, 0x00, 0x37, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x02,
    0x00, 0x00, 0x00, 0x20, 0x00, 0x05, 0x00, 0x21, 0x00, 0x38, 0x00, 0x00, 0x00, 0x20, 0x00, 0x03, 0x00, 0x00, 0x00,
    0x21, 0x00, 0x39, 0x00, 0x3A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x21, 0x00, 0x3D, 0x00, 0x3E, 0x00, 0x01, 0x00, 0x05,
    0x00, 0x1C, 0x00, 0x3F, 0x00, 0x40, 0x00, 0x02, 0x00, 0x41, 0x00, 0x00, 0x00, 0x0A, 0x00, 0x02, 0xFC, 0x00, 0x1F,
    0x01, 0x40, 0x07, 0x00, 0x42, 0x00, 0x04, 0x00, 0x43, 0x00, 0x44, 0x00, 0x03, 0x00, 0x36, 0x00, 0x00, 0x00, 0xCB,
    0x00, 0x05, 0x00, 0x05, 0x00, 0x00, 0x00, 0x4E, 0x2B, 0x10, 0x2E, 0x10, 0x2F, 0xB6, 0x00, 0x0B, 0x12, 0x0C, 0xB6,
    0x00, 0x0D, 0x4D, 0x2C, 0xB8, 0x00, 0x05, 0x3E, 0x1D, 0x9B, 0x00, 0x31, 0xB2, 0x00, 0x07, 0x1D, 0xB9, 0x00, 0x08,
    0x02, 0x00, 0xC0, 0x00, 0x09, 0x3A, 0x04, 0xB2, 0x00, 0x0E, 0x1D, 0xB9, 0x00, 0x0F, 0x02, 0x00, 0x57, 0xB2, 0x00,
    0x07, 0x1D, 0xB9, 0x00, 0x0F, 0x02, 0x00, 0x57, 0x2A, 0x2B, 0x19, 0x04, 0x03, 0x19, 0x04, 0xBE, 0xB6, 0x00, 0x10,
    0xB0, 0xBB, 0x00, 0x11, 0x59, 0x2C, 0xB7, 0x00, 0x12, 0xBF, 0x00, 0x00, 0x00, 0x03, 0x00, 0x37, 0x00, 0x00, 0x00,
    0x22, 0x00, 0x08, 0x00, 0x00, 0x00, 0x25, 0x00, 0x0E, 0x00, 0x27, 0x00, 0x13, 0x00, 0x28, 0x00, 0x17, 0x00, 0x2A,
    0x00, 0x25, 0x00, 0x2B, 0x00, 0x2F, 0x00, 0x2C, 0x00, 0x39, 0x00, 0x2D, 0x00, 0x45, 0x00, 0x2F, 0x00, 0x38, 0x00,
    0x00, 0x00, 0x34, 0x00, 0x05, 0x00, 0x25, 0x00, 0x20, 0x00, 0x45, 0x00, 0x46, 0x00, 0x04, 0x00, 0x00, 0x00, 0x4E,
    0x00, 0x39, 0x00, 0x3A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x4E, 0x00, 0x3D, 0x00, 0x3E, 0x00, 0x01, 0x00, 0x0E, 0x00,
    0x40, 0x00, 0x47, 0x00, 0x3E, 0x00, 0x02, 0x00, 0x13, 0x00, 0x3B, 0x00, 0x3F, 0x00, 0x40, 0x00, 0x03, 0x00, 0x41,
    0x00, 0x00, 0x00, 0x09, 0x00, 0x01, 0xFD, 0x00, 0x45, 0x07, 0x00, 0x2A, 0x01, 0x00, 0x48, 0x00, 0x00, 0x00, 0x04,
    0x00, 0x01, 0x00, 0x11, 0x00, 0x30, 0x00, 0x00, 0x00, 0x02, 0x00, 0x49, 0x00, 0x01, 0x00, 0x4A, 0x00, 0x4B, 0x00,
    0x01, 0x00, 0x36, 0x00, 0x00, 0x00, 0x7C, 0x00, 0x04, 0x00, 0x03, 0x00, 0x00, 0x00, 0x22, 0xBB, 0x00, 0x01, 0x59,
    0xBB, 0x00, 0x13, 0x59, 0xB7, 0x00, 0x14, 0x12, 0x15, 0xB6, 0x00, 0x16, 0x2B, 0xB6, 0x00, 0x16, 0xB6, 0x00, 0x17,
    0xB7, 0x00, 0x18, 0xB0, 0x4D, 0x2A, 0x2B, 0xB7, 0x00, 0x1A, 0xB0, 0x00, 0x01, 0x00, 0x00, 0x00, 0x1A, 0x00, 0x1B,
    0x00, 0x19, 0x00, 0x03, 0x00, 0x37, 0x00, 0x00, 0x00, 0x0E, 0x00, 0x03, 0x00, 0x00, 0x00, 0x34, 0x00, 0x1B, 0x00,
    0x35, 0x00, 0x1C, 0x00, 0x36, 0x00, 0x38, 0x00, 0x00, 0x00, 0x20, 0x00, 0x03, 0x00, 0x1C, 0x00, 0x06, 0x00, 0x4C,
    0x00, 0x4D, 0x00, 0x02, 0x00, 0x00, 0x00, 0x22, 0x00, 0x39, 0x00, 0x3A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x22, 0x00,
    0x3D, 0x00, 0x3E, 0x00, 0x01, 0x00, 0x41, 0x00, 0x00, 0x00, 0x06, 0x00, 0x01, 0x5B, 0x07, 0x00, 0x19, 0x00, 0x00,
    0x00, 0x4E, 0x00, 0x4F, 0x00, 0x02, 0x00, 0x36, 0x00, 0x00, 0x01, 0x97, 0x00, 0x05, 0x00, 0x07, 0x00, 0x00, 0x00,
    0x8D, 0xB2, 0x00, 0x0E, 0xC6, 0x00, 0x04, 0xB1, 0xBB, 0x00, 0x1B, 0x59, 0xB7, 0x00, 0x1C, 0xB3, 0x00, 0x0E, 0xBB,
    0x00, 0x1B, 0x59, 0xB7, 0x00, 0x1C, 0xB3, 0x00, 0x07, 0xBB, 0x00, 0x1D, 0x59, 0xBB, 0x00, 0x06, 0x59, 0x2B, 0xB7,
    0x00, 0x0A, 0xB7, 0x00, 0x1E, 0x4D, 0x11, 0x10, 0x00, 0xBC, 0x08, 0x3A, 0x05, 0x2C, 0xB6, 0x00, 0x1F, 0x59, 0x4E,
    0xC6, 0x00, 0x50, 0x2D, 0xB6, 0x00, 0x20, 0x99, 0x00, 0x06, 0xA7, 0xFF, 0xF0, 0xBB, 0x00, 0x21, 0x59, 0x11, 0x10,
    0x00, 0xB7, 0x00, 0x22, 0x3A, 0x06, 0x2C, 0x19, 0x05, 0xB6, 0x00, 0x23, 0x59, 0x36, 0x04, 0x9E, 0x00, 0x10, 0x19,
    0x06, 0x19, 0x05, 0x03, 0x15, 0x04, 0xB6, 0x00, 0x24, 0xA7, 0xFF, 0xEA, 0xB2, 0x00, 0x0E, 0x2D, 0xB6, 0x00, 0x25,
    0xB9, 0x00, 0x26, 0x02, 0x00, 0x57, 0xB2, 0x00, 0x07, 0x19, 0x06, 0xB6, 0x00, 0x27, 0xB9, 0x00, 0x26, 0x02, 0x00,
    0x57, 0xA7, 0xFF, 0xAD, 0x2C, 0xB6, 0x00, 0x28, 0xB1, 0x00, 0x00, 0x00, 0x03, 0x00, 0x37, 0x00, 0x00, 0x00, 0x3E,
    0x00, 0x0F, 0x00, 0x00, 0x00, 0x3C, 0x00, 0x07, 0x00, 0x3E, 0x00, 0x11, 0x00, 0x3F, 0x00, 0x1B, 0x00, 0x40, 0x00,
    0x2B, 0x00, 0x43, 0x00, 0x32, 0x00, 0x44, 0x00, 0x3B, 0x00, 0x45, 0x00, 0x45, 0x00, 0x46, 0x00, 0x51, 0x00, 0x47,
    0x00, 0x5D, 0x00, 0x48, 0x00, 0x6A, 0x00, 0x4A, 0x00, 0x77, 0x00, 0x4B, 0x00, 0x85, 0x00, 0x4C, 0x00, 0x88, 0x00,
    0x4D, 0x00, 0x8C, 0x00, 0x4E, 0x00, 0x38, 0x00, 0x00, 0x00, 0x48, 0x00, 0x07, 0x00, 0x51, 0x00, 0x34, 0x00, 0x50,
    0x00, 0x51, 0x00, 0x06, 0x00, 0x5A, 0x00, 0x2E, 0x00, 0x52, 0x00, 0x40, 0x00, 0x04, 0x00, 0x00, 0x00, 0x8D, 0x00,
    0x39, 0x00, 0x3A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8D, 0x00, 0x53, 0x00, 0x46, 0x00, 0x01, 0x00, 0x2B, 0x00, 0x62,
    0x00, 0x54, 0x00, 0x55, 0x00, 0x02, 0x00, 0x38, 0x00, 0x55, 0x00, 0x56, 0x00, 0x57, 0x00, 0x03, 0x00, 0x32, 0x00,
    0x5B, 0x00, 0x58, 0x00, 0x46, 0x00, 0x05, 0x00, 0x41, 0x00, 0x00, 0x00, 0x66, 0x00, 0x06, 0x07, 0xFF, 0x00, 0x2A,
    0x00, 0x06, 0x07, 0x00, 0x2C, 0x07, 0x00, 0x09, 0x07, 0x00, 0x1D, 0x00, 0x00, 0x07, 0x00, 0x09, 0x00, 0x00, 0xFF,
    0x00, 0x12, 0x00, 0x06, 0x07, 0x00, 0x2C, 0x07, 0x00, 0x09, 0x07, 0x00, 0x1D, 0x07, 0x00, 0x59, 0x00, 0x07, 0x00,
    0x09, 0x00, 0x00, 0xFC, 0x00, 0x0B, 0x07, 0x00, 0x21, 0xFF, 0x00, 0x18, 0x00, 0x07, 0x07, 0x00, 0x2C, 0x07, 0x00,
    0x09, 0x07, 0x00, 0x1D, 0x07, 0x00, 0x59, 0x01, 0x07, 0x00, 0x09, 0x07, 0x00, 0x21, 0x00, 0x00, 0xFF, 0x00, 0x1D,
    0x00, 0x06, 0x07, 0x00, 0x2C, 0x07, 0x00, 0x09, 0x07, 0x00, 0x1D, 0x07, 0x00, 0x59, 0x00, 0x07, 0x00, 0x09, 0x00,
    0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x04, 0x00, 0x01, 0x00, 0x5A, 0x00, 0x0A, 0x00, 0x5B, 0x00, 0x5C, 0x00, 0x01,
    0x00, 0x36, 0x00, 0x00, 0x00, 0x8C, 0x00, 0x02, 0x00, 0x03, 0x00, 0x00, 0x00, 0x2D, 0x03, 0x3C, 0xB2, 0x00, 0x0E,
    0xB9, 0x00, 0x29, 0x01, 0x00, 0x3D, 0x1B, 0x1C, 0xA2, 0x00, 0x1E, 0xB2, 0x00, 0x0E, 0x1B, 0xB9, 0x00, 0x08, 0x02,
    0x00, 0xC0, 0x00, 0x2A, 0x2A, 0xB6, 0x00, 0x2B, 0x99, 0x00, 0x05, 0x1B, 0xAC, 0x84, 0x01, 0x01, 0xA7, 0xFF, 0xE3,
    0x02, 0xAC, 0x00, 0x00, 0x00, 0x03, 0x00, 0x37, 0x00, 0x00, 0x00, 0x16, 0x00, 0x05, 0x00, 0x00, 0x00, 0x51, 0x00,
    0x10, 0x00, 0x52, 0x00, 0x23, 0x00, 0x53, 0x00, 0x25, 0x00, 0x51, 0x00, 0x2B, 0x00, 0x56, 0x00, 0x38, 0x00, 0x00,
    0x00, 0x20, 0x00, 0x03, 0x00, 0x02, 0x00, 0x29, 0x00, 0x5D, 0x00, 0x40, 0x00, 0x01, 0x00, 0x0B, 0x00, 0x20, 0x00,
    0x52, 0x00, 0x40, 0x00, 0x02, 0x00, 0x00, 0x00, 0x2D, 0x00, 0x3D, 0x00, 0x3E, 0x00, 0x00, 0x00, 0x41, 0x00, 0x00,
    0x00, 0x0B, 0x00, 0x03, 0xFD, 0x00, 0x0B, 0x01, 0x01, 0x19, 0xF9, 0x00, 0x05, 0x00, 0x01, 0x00, 0x5E, 0x00, 0x00,
    0x00, 0x02, 0x00, 0x5F,
    //
};

Jvm::Jvm() : common(Common::getInstance()), properties(Properties::getInstance()) {}

Error Jvm::start() {
    if (!load()) {
        return ERR_LOAD_JVM_DLL;
    }
    if (!createJavaVM()) {
        return ERR_CREATE_JVM;
    }
    setupClassLoader();
    if (!runMainClass()) {
        return ERR_MAIN_CLASS_NOT_FOUND;
    }
    return ERR_OK;
}

bool Jvm::load() {
    if (ptrCreateJavaVM) {
        return true;
    }

    // expand java home
    std::list<WString> javaHome = properties.getJavaHome();
    if (javaHome.empty()) {
        throw std::runtime_error("exe.javaHome is not set!");
    }

    // find jvm.dll and load
    WString jvmLibSuffix[] = {
        L"\\bin\\client\\jvm.dll",
        L"\\bin\\server\\jvm.dll",
        L"\\jre\\bin\\client\\jvm.dll",
        L"\\jre\\bin\\server\\jvm.dll",
    };
    for (WString home : javaHome) {
        for (WString path : jvmLibSuffix) {
            WString fullPath = home + path;
            if (common.isFileExists(fullPath)) {
                WString binDir = fullPath.substr(0, fullPath.rfind(L"\\bin") + 4);
                if (debugEnable) {
                    common.debug(L"load: " + fullPath);
                }
                SetDllDirectoryW(nullptr);
                // Call SetCurrentDirectory to allow jvm.dll to load the corresponding runtime libraries.
                SetCurrentDirectory(binDir.c_str());
                HMODULE module = LoadLibrary(fullPath.data());
                if (module) {
                    ptrCreateJavaVM = (PtrCreateJavaVM)GetProcAddress(module, "JNI_CreateJavaVM");
                    if (ptrCreateJavaVM) {
                        return true;
                    }
                }
            }
        }
    }

    return ptrCreateJavaVM != nullptr;
}

bool Jvm::createJavaVM() {
    // prepare vm options
    std::list<WString> vmOptions = properties.getVmOptions();

    // add classpath option
    WString fullClassPath = properties.getClassPath();
    if (!fullClassPath.empty()) {
        vmOptions.push_back(L"-Djava.class.path=" + fullClassPath);
    }

    // add user.dir
    vmOptions.push_back(L"-Duser.dir=" + common.getExeDir());

    std::vector<JavaVMOption> opts;
    for (WString opt : vmOptions) {
        JavaVMOption item;
        item.optionString = _strdup(common.wstring2utf8(opt).c_str());
        item.extraInfo = 0;
        opts.push_back(item);
    }

    JavaVMInitArgs initArgs;
    initArgs.version = JNI_VERSION_1_6;
    initArgs.options = opts.data();
    initArgs.nOptions = static_cast<jint>(opts.size());
    initArgs.ignoreUnrecognized = JNI_FALSE;
    return ptrCreateJavaVM(&jvm, &env, &initArgs) == JNI_OK;
}

void Jvm::setupClassLoader() {
    // 加载 EMBEDDED_JAR
    HRSRC hs = FindResource(NULL, EMBEDDED_JAR, RT_RCDATA);
    if (hs == NULL || SizeofResource(NULL, hs) == 0)
        return;

    HGLOBAL hMemory = LoadResource(NULL, hs);
    DWORD dwSize = SizeofResource(NULL, hs);
    LPVOID lpAddress = LockResource(hMemory);
    BYTE *bytes = new BYTE[dwSize];
    memcpy(bytes, lpAddress, dwSize);
    FreeResource(hMemory);

    // 获取 SystemClassLoader.class
    jclass classLoaderClass = env->FindClass("java/lang/ClassLoader");
    if (!classLoaderClass) {
        common.debug(L"Could not access classloader");
        return;
    }

    jmethodID getSystemClassLoader =
        env->GetStaticMethodID(classLoaderClass, "getSystemClassLoader", "()Ljava/lang/ClassLoader;");
    if (!getSystemClassLoader) {
        common.debug(L"Could not access classloader method");
        return;
    }

    // ClassLoader.getSystemClasssLoader();
    jobject loader = env->CallStaticObjectMethod(classLoaderClass, getSystemClassLoader);
    loader = env->NewGlobalRef(loader);

    // DefineClass EmbeddedClassLoader
    jclass embeddedClassLoaderClass =
        env->DefineClass("jstart/exe/EmbeddedClassLoader", loader, (const jbyte *)EMBEDDED_CLASS_LOADER_CLASS,
                         sizeof(EMBEDDED_CLASS_LOADER_CLASS));
    if (!embeddedClassLoaderClass) {
        common.showMessageBox(true, L"Define Class Loader failed!");
        return;
    }
    jmethodID newEmbeddedClassLoader = env->GetMethodID(embeddedClassLoaderClass, "<init>", "()V"); //（类,属性名.签名)
    if (!newEmbeddedClassLoader) {
        common.showMessageBox(true, L"Constructor not found!!");
        return;
    }

    // embeddedClassLoader = new EmbeddedClassLoader();
    embeddedClassLoader = env->NewObject(embeddedClassLoaderClass, newEmbeddedClassLoader);
    // embeddedClassLoader.loadEmbeddedJar(byte[]);
    jmethodID loadEmbeddedJar = env->GetMethodID(embeddedClassLoaderClass, "loadEmbeddedJar", "([B)V");
    jbyteArray jarBytes = env->NewByteArray(dwSize);
    env->SetByteArrayRegion(jarBytes, 0, dwSize, (const jbyte *)bytes);
    // embeddedClassLoader.loadEmbeddedJar();
    env->CallObjectMethod(embeddedClassLoader, loadEmbeddedJar, jarBytes);

    // 保存方法 embeddedClassLoader.findClass
    findClassMethod = env->GetMethodID(embeddedClassLoaderClass, "findClass", "(Ljava/lang/String;)Ljava/lang/Class;");
}

bool Jvm::runMainClass() {
    WString mainClass = properties.getMainClass();
    if (mainClass.empty()) {
        return false;
    }

    std::string mainClassName = common.wstring2utf8(mainClass);
    jclass jclassMain = env->FindClass(mainClassName.c_str());
    if (!jclassMain && findClassMethod) {
        jobject rtn = env->CallObjectMethod(embeddedClassLoader, findClassMethod, env->NewStringUTF("jstart.exe.Main"));
        if (rtn) {
            jclassMain = (jclass)rtn;
        }
    }
    if (!jclassMain) {
        return false;
    }

    jmethodID mainMethod = env->GetStaticMethodID(jclassMain, "main", "([Ljava/lang/String;)V");
    if (!mainMethod) {
        return false;
    }

    std::list<WString> mainArgs = properties.getMainArgs();
    size_t size = mainArgs.size();
    jobjectArray args = (jobjectArray)env->NewObjectArray(static_cast<jsize>(size), env->FindClass("java/lang/String"),
                                                          env->NewStringUTF(""));
    int i = 0;
    for (WString arg : mainArgs) {
        env->SetObjectArrayElement(args, static_cast<jsize>(i++), env->NewStringUTF(common.wstring2utf8(arg).c_str()));
    }
    env->ExceptionClear();
    env->CallStaticVoidMethod(jclassMain, mainMethod, args);
    jthrowable exception = env->ExceptionOccurred();
    if (exception) {
        // throw std::runtime_error("Run main method has exception!");
        jclass jexcpteClass = env->FindClass("java/lang/Exception");
        jmethodID getMessage = env->GetMethodID(jexcpteClass, "getMessage", "()Ljava/lang/String;");
        jstring msg = (jstring)env->CallObjectMethod(exception, getMessage);
        std::string err(env->GetStringUTFChars(msg, false));
        common.showMessageBox(true, WString(err.begin(), err.end()));
    }
    jvm->DestroyJavaVM();
    return true;
}
